import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

/**
* 继承的Reducer类有四个泛型参数,2对kv
 * 第一对kv:类型要与Mapper输出类型一致：LongWritable, LongWritable
 * 第二对kv:自己设计决定输出的结果数据是什么类型：LongWritable, LongWritable
* */
public class SortNumReducer extends Reducer<LongWritable,LongWritable,LongWritable,LongWritable> {
    //全局变量，初始化行号1
    private static LongWritable linesum = new LongWritable(1);

    @Override
    protected void reduce(LongWritable key, Iterable<LongWritable> values, Context context) throws IOException, InterruptedException {
        //遍历key对应的values，然后行号+1
        for(LongWritable v:values){
            //输出行号，当前key值
            context.write(linesum,key);
            linesum = new LongWritable(linesum.get()+ 1);
        }
    }

}